Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KeePass header check for testing remote download (#10910) #10915

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

t-h-e
Copy link
Contributor

@t-h-e t-h-e commented Jun 17, 2024

Verify downloaded file.
Context: #10910

Screenshots

Testing strategy

Test a command that downloads a random file that is not a KeePass database.

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

Copy link
Member

@hifi hifi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit rusty with KeePassXC code but added some comments. Otherwise I think it'll do the correct thing!

// Read public headers
QString error;
QScopedPointer<Database> db(new Database());
return db->open(filePath, nullptr, &error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could inline this since you have only a single call for it and use the error string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if I should use the error string, as it can be quite long and may not fit in the message box. I added the error anyway, as it is better to have it rather than leave the user in the dark.

I did not inline the method though, as I prefer having a named method, rather than calling Database::open with a nullptr as second parameter, which implies reading the headers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are repeating this pattern we should introduce a Database::readHeaders function that takes care of the particulars.

}

if (!hasValidPublicHeaders(result.filePath)) {
m_ui->messageWidget->showMessage(tr("Download finished, but file failed KeePass header check. File is not a "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the actual error from database open here. "KeePass header check" is quite a technical error message as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have adapted the error message

@droidmonkey droidmonkey added this to the v2.8.0 milestone Jun 19, 2024
@hifi
Copy link
Member

hifi commented Jun 19, 2024

LGTM, I haven't yet tested this but the code look fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants